import { fileGet, filePost, post } from '@/request/http'
import store from '@/store'

const url = '/FTKJWLHYPT/statistics/'

/**
 * 列表查询
 * @returns {Promise | Promise<unknown> | Promise | Promise | Promise | Window.Promise | *}
 */
export const queryShippingStatus = ({
  contractNo,
  wabPlaceof,
  wabReceplace,
  ctrNo,
  signingStartTime,
  signingEndTime,
  shippingCompany,
  oneBoatATAStart,
  oneBoatATAEnd,
  oneBoatDOFStart,
  oneBoatDOFEnd,
  client,
  supplier,
  brand,
  clients,
  suppliers,
  brands,
  loadStartTime,
  loadEndTime,
  wabCompleteTimeStart,
  wabCompleteTimeEnd,
  wayNo,
  index,
  size,
  source,
  fltId,
}) =>
  post(url + 'queryShippingStatus', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          contractNo,
          wabPlaceof,
          wabReceplace,
          shippingCompany,
          ctrNo,
          signingStartTime,
          signingEndTime,
          oneBoatATAStart,
          oneBoatATAEnd,
          oneBoatDOFStart,
          oneBoatDOFEnd,
          client,
          supplier,
          brand,
          loadStartTime,
          loadEndTime,
          wayNo,
          wabCompleteTimeStart,
          wabCompleteTimeEnd,
          //平台：0，供应商：1， 集团：2， 糖厂：3， 货主：4
          source:
            store.state.user.ROLE_TYPE_DX_H == 'p'
              ? 0
              : store.state.user.ROLE_TYPE_DX_H == 'g'
                ? 1
                : store.state.user.ROLE_TYPE_DX_H == 'c'
                  ? 2
                  : store.state.user.ROLE_TYPE_DX_H == 'j'
                    ? 3
                    : 4,
          fltId: store.state.user.FLT_UUID_DX_H,
          dptId: store.state.user.DPTID_DX_H,
          clients,
          suppliers,
          brands,
        },
      },
      PageIndex: {
        FTKJWLHYPT: index,
      },
      PageSize: {
        FTKJWLHYPT: size,
      },
    },
  })

/**
 *
 * @param contractNo
 * @param client
 * @param supplier
 * @param brand
 * @param loadStartTime
 * @param loadEndTime
 * @param wayNo
 * @param source
 * @param fltId
 * @param wabIds
 * @param nos
 * @param roleType
 * @returns {Promise | Promise<unknown>}
 */
export const shippingExportExcel = ({ contractNo, client, supplier, brand, loadStartTime, loadEndTime, wayNo, source, fltId, wabIds, nos, roleType }) =>
  filePost(url + 'shippingExportExcel', {
    contractNo,
    client,
    supplier,
    brand,
    loadStartTime,
    loadEndTime,
    wayNo,
    source,
    fltId,
    wabIds,
    nos,
    roleType,
  })

/**
 * 修改箱号和批次
 * @param id
 * @param ctrNo
 * @param wabProBatch
 * @returns {Promise | Promise<unknown>}
 */
export const updateNoAndBatch = ({ id, ctrNo, wabProBatch }) =>
  post(url + 'updateNoAndBatch', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          id,
          ctrNo,
          wabProBatch,
        },
      },
    },
  })

/**
 *
 * @param ids id集合
 * @param supplierName 供应商名称
 * @returns {Promise | Promise<unknown>}
 */
export const shippingLetterExportExcel = (ids, supplierName) =>
  filePost(url + 'shippingLetterExportExcel', {
    ids,
    supplierName,
  })

/**
 *
 * @param client
 * @param supplier
 * @param status
 * @param contractNo
 * @param singedStartTime
 * @param singedEndTime
 * @param index
 * @param size
 * @param unloadingStartTime
 * @param unloadingEndTime
 * @param xhStartTime
 * @param xhEndTime
 * @param isCompleteTransportation
 * @param invoiceStatus
 * @param receiveDateS
 * @param receiveDateE
 * @param payDateS
 * @param payDateE
 * @param payStatus
 * @param clients
 * @param suppliers
 * @returns {Promise | Promise<unknown>}
 */
export const fundflowdetailsQuery = ({
  client,
  supplier,
  status,
  contractNo,
  singedStartTime,
  singedEndTime,
  index,
  size,
  unloadingStartTime,
  unloadingEndTime,
  xhStartTime,
  xhEndTime,
  isCompleteTransportation,
  invoiceStatus,
  receiveDateS,
  receiveDateE,
  payDateS,
  payDateE,
  payStatus,
  clients,
  suppliers,
}) =>
  post(url + 'fundflowdetailsQuery', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          client,
          supplier,
          status,
          contractNo,
          singedStartTime,
          singedEndTime,
          unloadingStartTime,
          unloadingEndTime,
          xhStartTime,
          xhEndTime,
          isCompleteTransportation,
          invoiceStatus,
          receiveDateS,
          receiveDateE,
          payDateS,
          payDateE,
          payStatus,
          clients,
          suppliers,
          //平台：0，供应商：1， 集团：2， 糖厂：3， 货主：4
          source:
            store.state.user.ROLE_TYPE_DX_H == 'p'
              ? 0
              : store.state.user.ROLE_TYPE_DX_H == 'g'
                ? 1
                : store.state.user.ROLE_TYPE_DX_H == 'c'
                  ? 2
                  : store.state.user.ROLE_TYPE_DX_H == 'j'
                    ? 3
                    : 4,
          fltId: store.state.user.FLT_UUID_DX_H,
          dptId: store.state.user.DPTID_DX_H,
        },
      },
      PageIndex: {
        FTKJWLHYPT: index,
      },
      PageSize: {
        FTKJWLHYPT: size,
      },
    },
  })

export const fundflowdetailExportExcel = ({ nos, index, size }) =>
  filePost(url + 'fundflowdetailExportExcel', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          nos,
        },
      },
    },
  })

// 列表数据接口
export const goodsBrandListA = data =>
  post('/FTKJWLHYPT/base/goodsBrandList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          brandName: data.brandName,
          dptId: store.state.user.DPTID_DX_H == null ? -1 : store.state.user.DPTID_DX_H,
          fltId: store.state.user.FLT_UUID_DX_H,
        },
      },
    },
  })

/**
 * 发运情况汇总保存
 * @param list
 * @returns {Promise | Promise<unknown>}
 */
export const saveShipEditData = list => post('/FTKJWLHYPT/statistics/saveShipEditData', list)

/**
 * 资金流动明细修改运单税率
 * @param rate
 * @param ids
 * @returns {Promise | Promise<unknown>}
 */
export const updateWabRate = ({ rate, ids, nos }) =>
  post('/FTKJWLHYPT/statistics/updateWabRate', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          rate,
          ids,
          nos,
        },
      },
    },
  })

/**
 * 陆运情况汇总
 * @param index
 * @param size
 * @param contractNo
 * @param brand
 * @param brands
 * @param drvName
 * @param drvNames
 * @param trkNo
 * @param trkNos
 * @param loadStartTime
 * @param loadEndTime
 * @param unloadStartTime
 * @param unloadEndTime
 * @param wabPlaceof
 * @param wabReceplace
 * @param wayIds
 * @param nos
 * @param cmtSigningTimeStart
 * @param cmtSigningTimeEnd
 * @param supplier
 * @param upperClient
 * @param client
 * @returns {Promise | Promise<unknown>}
 */
export const queryWayShippingStatus = ({
  index,
  size,
  contractNo,
  brand,
  brands,
  drvName,
  drvNames,
  trkNo,
  trkNos,
  loadStartTime,
  loadEndTime,
  unloadStartTime,
  unloadEndTime,
  wabPlaceof,
  wabReceplace,
  wayIds,
  nos,
  cmtSigningTimeStart,
  cmtSigningTimeEnd,
  supplier,
  upperClient,
  client,
}) =>
  post(url + '/queryWayShippingStatus', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          contractNo,
          brand,
          drvName,
          trkNo,
          loadStartTime,
          loadEndTime,
          unloadStartTime,
          unloadEndTime,
          wabPlaceof,
          wabReceplace,
          wayIds,
          nos,
          cmtSigningTimeEnd,
          cmtSigningTimeStart,
          supplier,
          brands,
          trkNos,
          drvNames,
          upperClient,
          client,
        },
      },
      PageIndex: {
        FTKJWLHYPT: index,
      },
      PageSize: {
        FTKJWLHYPT: size,
      },
    },
  })
